package com.lap.analysis.file.handler;

import com.lap.analysis.source.entity.ClassInfo;
import com.lap.analysis.source.entity.FileInfo;
import com.lap.analysis.tools.ProjectUtil;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * 测试Handler
 *
 * @author Shuisheng Lao(劳水生)
 * @version 0.0.1
 */
public class TestFileHandler implements AbstractFileHandler {

  @Override
  public List<FileInfo> execute(ClassInfo classInfo) {
    if (Objects.isNull(classInfo)) return Collections.emptyList();

    TestFileBuilder builder = new TestFileBuilder.Default();
    TestFileDirector director = new TestFileDirector(builder);
    String content = director.construct(classInfo);

    String path = ProjectUtil.getTestPath(classInfo.getPackageName());
    String fileName = classInfo.getFileName() + "Test.java";

    return List.of(new FileInfo(path, fileName, content));
  }
}
